﻿/******************************************************/
// MarketNewsDetailPage プレゼンテーションクラス  
/******************************************************/

using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using MAA.Business;
using System.Web.UI.WebControls;
using System.Text;

namespace MAA.Presentation.PRL.News
{
    public partial class MarketNewsDetailPage : System.Web.UI.Page
    {
        private ResourceManager rm = new ResourceManager("MAA.Presentation.language", System.Reflection.Assembly.GetExecutingAssembly());
        private CultureInfo m_JapanCulture = new CultureInfo("ja-JP");
        private CultureInfo m_VietnameCulture = new CultureInfo("vi");

        private void UpdateUI()
        {
            langBy.Text = rm.GetString("langBy");
            langDateBuy.Text = rm.GetString("langDateBuy");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["language"] == null)
            {
                Session["language"] = "vi";
            }
            if (Session["language"].Equals("vi"))
            {
                Thread.CurrentThread.CurrentUICulture = m_VietnameCulture;
                UpdateUI();
            }
            if (Session["language"].Equals("jp"))
            {
                Thread.CurrentThread.CurrentUICulture = m_JapanCulture;
                UpdateUI();
            }
            if (IsPostBack) return;

            int newsID = Convert.ToInt32(Request.QueryString["newsID"]);

            BOLNews bolNews = new BOLNews();
            DataTable tblNews = new DataTable();
            string message = "";
            string lang = Session["language"].ToString();
            // View detail information of a market news
            if (bolNews.viewNewsDetail(lang,newsID, out tblNews, out message) == true)
            {
                if (tblNews.Rows.Count > 0)
                {
                    for (int i = 0; i < tblNews.Rows.Count; ++i)
                    {
                        lblTitle.Text = Convert.ToString(tblNews.Rows[i]["Title"]);
                        lblPostDate.Text = Convert.ToString(tblNews.Rows[i]["UpdateTime"]);
                        lblPosterName.Text = Convert.ToString(tblNews.Rows[i]["Name"]);
                        impPicture.ImageUrl = Convert.ToString(tblNews.Rows[i]["Image"]);
                        string content = Convert.ToString(tblNews.Rows[i]["Content"]);
                        StringBuilder sb = new StringBuilder(content);
                        lblContent.Text = sb.ToString().Replace("\n", "<br />");
                    }
                }
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(),
                    "Alert", "<script>alert('" + PRLCommon.ChangeLanguageMessage(message) + "')</script>", false);
            }

            // View information of 4 random market news
            DataTable tblMoreNews = new DataTable();
            string messageNews = "";
            if (!bolNews.viewNewsRandom(lang, newsID, out tblMoreNews, out messageNews))
            {
                tblNewsInfo.DataSource = null;
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(),
                    "Alert", "<script>alert('" + PRLCommon.ChangeLanguageMessage(messageNews) + "')</script>", false);
            }
            else
            {
                DataView newsDataView = new DataView(tblMoreNews);
                PagedDataSource newsItems = new PagedDataSource();
                newsItems.DataSource = newsDataView;
                tblNewsInfo.DataSource = newsItems;
            }
            tblNewsInfo.DataBind();
        }
    }
}